//
//  BIZCCLiveNavbarViews.m
//  biz
//
//  Created by zhangfuwei on 2017/5/3.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZCCLiveNavbarViews.h"
#import "BIZPaomaLabel.h"

@implementation BIZCCLiveNavbarViews{
    NSString        *_roomName;
    UIImageView     *_labaImgV;
    BIZPaomaLabel    *_titleLable;
    UIButton        *_backButton;
    
    BIZCCLiveNavbarViewsBackBlock  _block;
}

- (instancetype)initWithRoomName:(NSString *)roomName backBlock:(BIZCCLiveNavbarViewsBackBlock)block
{
    self = [super init];
    if (self) {
        _block      = block;
        _roomName   = roomName;
        self.backgroundColor = [UIColor clearColor];
        [self loadUI];
    }
    return self;
}

- (void)loadUI {
    
    _labaImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ccLiveRoom_laba"]];
    
    _titleLable = [[BIZPaomaLabel alloc] initWithFrame:CGRectMake(40, 32, Main_Screen_Width-90, 20) withTitle:_roomName];
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backButton setImage:[UIImage imageNamed:@"ccLiveRoom_close"] forState:UIControlStateNormal];
    
    [_backButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:_labaImgV];
    [self addSubview:_titleLable];
    [self addSubview:_backButton];
    
}

- (void)setRoomName:(NSString *)roomName {
    _roomName = roomName;
    if (_titleLable) {
        [_titleLable removeFromSuperview];
        _titleLable = nil;
    }
    _titleLable = [[BIZPaomaLabel alloc] initWithFrame:CGRectMake(40, 32, Main_Screen_Width-90, 20) withTitle:roomName];
    [self addSubview:_titleLable];

    [self layoutIfNeeded];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [_labaImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.bottom.equalTo(self).offset(-1*15);
        make.width.height.equalTo(@18);
    }];
    
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-1*15);
        make.width.height.equalTo(@24);
        make.centerY.equalTo(_labaImgV);
    }];
    
//    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_labaImgV.mas_right).offset(12);
//        make.right.equalTo(_backButton.mas_left).offset(-1*5);
//        make.centerY.equalTo(_labaImgV);
//    }];
}

- (void)btnClick:(UIButton *)btn {
    NSLog(@"%s",__func__);
    !_block ?:_block();
}


@end
